package com.tony.juc;

import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: CopyOnWriteArrayListDemo001
 * @Auther: 皮蛋布丁
 * @Date: 2022/04/16/11:08
 * @Description: 并发单值集合类
 */
public class CopyOnWriteArrayListDemo001 {

    public static void main(String[] args) {

        /*List<String> all = new CopyOnWriteArrayList<>(); //创建一个List集合
        for (int num = 0; num < 10; num++) { //创建10个线程
            new Thread(()->{
                for (int i = 0; i < 10; i++) { //进行数据的循环更新操作
                    all.add("【" + Thread.currentThread().getName() + "】皮蛋布丁"); //添加集合数据
                    System.out.println(all); //输出全部的数据内容
                }
            },"集合操作线程_" + num).start(); //线程启动
        }*/

        Set<String> all = new CopyOnWriteArraySet<>(); //创建一个Set集合
        for (int num = 0; num < 10; num++) {
            new Thread(()->{
                for (int i = 0; i < 10; i++) {
                    all.add("【" + Thread.currentThread().getName() + "】皮蛋布丁");
                    System.out.println(all);
                }
            },"集合操作线程_" + num).start();
        }


    }
}
